<?php

namespace Rblog\Module\Admin\Controller;

class Common extends \Rexzy\App\Controller {
    
    /**
     * 构造函数先判断是否登录，否则跳转到登录页面
     */
    public function __construct() {
        parent::__construct();
        $userLib = new \Rblog\Module\Admin\Lib\User();
        $actionName = \Rexzy::getCore( 'actionName' );
        $noLoginAction = array(
            'Login',
            'Verify',
            'Openid',
        );
        if ( ( ! $userLib->isLogged() ) && ( ! in_array( $actionName, $noLoginAction ) ) ) {
            $this->response->location( \Rexzy::url( 'user/login' ) );
        }
        if ( ( $userLib->isLogged() ) && ( $actionName == 'Login' ) ) {
            $this->response->location( \Rexzy::url( 'admin/index' ) );
        }
        if ( $actionName !== 'Login' ) {
            $userLib->login('userid', $this->request->input( 'userid', 'c'), 1800 );
        }
        
    }
}
